﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Program15_GDI
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 画直线
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLine_Click(object sender, EventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();
            //创建画笔对象(比形，颜色)
            Pen pen = new Pen(Brushes.Red,5.0F);
            //pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
            //线条风格
            float[] dashValues = { 2, 4, 8, 16 };
            pen.DashPattern = dashValues;
            //画直线，建立坐标
            //Point p1 = new Point(30, 50);//x
            //Point p2 = new Point(800, 50);//y

            //绘制直线(画笔，坐标)
            g.DrawLine(pen,30,50,800,50);
            //g.DrawRectangle(pen, 300, 250, 300, 300);//在画板上画矩形,起始坐标为(10,10),宽100,高100
            //g.Clear(Color.Yellow);//画板背景颜色
        }

        private void btnRect_Click(object sender, EventArgs e)
        {
            //创建画板
            Graphics gp = this.CreateGraphics();
            //创建画笔
            Pen pen = new Pen(Brushes.Blue,5);
            //画出矩形
            gp.DrawRectangle(pen, 30, 70, 300, 300);
        }

        private void btnCircle_Click(object sender, EventArgs e)
        {
            //创建画板
            Graphics gp = this.CreateGraphics();
            //创建画笔
            Pen pen = new Pen(Brushes.Coral, 5);
            //画椭圆/圆形
            gp.DrawEllipse(pen, 30, 70, 300, 300);
        }

        private void btnSan_Click(object sender, EventArgs e)
        {
            //创建画板
            Graphics gp = this.CreateGraphics();
            //创建画笔(填充)
            SolidBrush bush = new SolidBrush(Color.Blue);
            //扇形
            gp.FillPie(bush, 50, 200, 200, 200,45,90);
            bush = new SolidBrush(Color.Red);
            gp.FillPie(bush, 50, 200, 200, 200, 135, 90);
            bush = new SolidBrush(Color.Yellow);
            gp.FillPie(bush, 50, 200, 200, 200, 180, 90);
            bush = new SolidBrush(Color.Azure);
            gp.FillPie(bush, 50, 200, 200, 200, 250, 170);
            //写字
            gp.DrawString("业界精英",new Font("宋体",14),Brushes.Black,new PointF(60,350));
        }
        private int i = 0;
        private void Form1_Paint(object sender, PaintEventArgs e)//绘图事件
        {
            i++;
            label1.Text = i.ToString();
        }

        private void label2_Click(object sender, EventArgs e)
        {
            label2.Text = ValidateCode.CreateVCode(4);
        }
    }
}
